#include "STC89C51RC_RD_PLUS.h"
#include "DEFINE.h"

//===============================

//==============================

#define ISP_IAP_BYTE_READ   1    
#define ISP_IAP_BYTE_PROGRAM 2   
#define ISP_IAP_SECTOR_ERASE 3   
#define WAIT_TIME   	 1       


uchar isp_read_byte(uint add)
{
	uchar addh, addl;
	uchar rdata;
        add=add+0x2000;
	addh = add >> 8;
	addl = add & 0xff;
	ISP_ADDRH = addh;
	ISP_ADDRL = addl;
	EA = 0;
	ISP_CONTR = WAIT_TIME | 0X80;
	ISP_CMD = ISP_IAP_BYTE_READ;
	ISP_TRIG = 0X46;
	ISP_TRIG = 0XB9;
	rdata = 0;
	rdata = ISP_DATA;

	EA = 1;
	return(rdata);
}
void isp_program_byte(uint add, uchar dat)
{
	uchar addh, addl;
	ISP_DATA = dat;
        add=add+0x2000;

	addh = add >> 8;
	addl = add & 0xff;
	ISP_ADDRH = addh;
	ISP_ADDRL = addl;
	EA = 0;
	ISP_CONTR = WAIT_TIME | 0X80;
	ISP_CMD = ISP_IAP_BYTE_PROGRAM;
	ISP_TRIG = 0X46;
	ISP_TRIG = 0XB9;
	ACC = 0;

	EA = 1;
}
void isp_erase_sector(uchar  num)
{
	
	uchar addh, addl;
        num=0;
	addh = 0x20;
	addl = 0x00;
	ISP_ADDRH = addh;
	ISP_ADDRL = addl;
	EA = 0;
	ISP_CONTR = WAIT_TIME | 0X80;
	ISP_CMD = ISP_IAP_SECTOR_ERASE;
	ISP_TRIG = 0X46;
	ISP_TRIG = 0XB9;
	ACC = 0;

	EA = 1;
}
















